﻿using UnityEngine;
using UnityEngine.UI;

namespace UnityView
{
    public class ScrollView : UIView
    {
        public ScrollRect ScrollRect;
        public LinearLayout ContentView;
        public RectTransform ContentTransform;

        public Orientation Orientation { set; get; }
        
        public RectMask2D Mask;

        public ScrollView(RectTransform parent, float width, string name = "Scroll View") : base(parent, name)
        {
            ScrollRect = UIObject.AddComponent<ScrollRect>();
            ScrollRect.vertical = true;
            ScrollRect.horizontal = false;
            ScrollRect.scrollSensitivity = 100f;
            ScrollRect.movementType = ScrollRect.MovementType.Clamped;

            ContentView = new LinearLayout(this);
            ContentView.Frame = new Frame(0, 0, width, 0);
            ContentTransform = ContentView.RectTransform;
            ContentView.Name = "Content View";
            ContentTransform.anchoredPosition = Vector2.zero;
            ScrollRect.content = ContentView.RectTransform;

            InternalBackgroundColor = Color.clear;
            Mask = UIObject.AddComponent<RectMask2D>();
        }
        
        public float ContentSize
        {
            set => ContentTransform.sizeDelta = new Vector2(ContentTransform.sizeDelta.x, value);
            get => ContentTransform.sizeDelta.y;
        }
        
        public void Reload()
        {

        }

        public void ScrollToTop()
        {
            ContentView.RectTransform.anchoredPosition = Vector2.zero;
        }

        public void Add(IViewLayout view)
        {

        }
    }

    public class HorizontalScrollView : UIView
    {

    }
}
